#include<SGE.h>
using namespace SGE;

#include "PlayState.h"
#include "FrontendState.h"
#include "GameoverState.h"

GameContext gameContext;
GameState* currentState = nullptr;
NextState nextState = Frontend;

void SGE_Initialize() 
{
}

void SGE_Terminate()
{
}

bool SGE_Update(float deltaTime)
{
	if(nextState != None)
	{
		//Unload current state
		if(currentState != nullptr)
		{
			currentState->Unload();
			delete currentState;
		}

		//Change state
		switch(nextState)
		{
		case Frontend:
			currentState = new FrontendState(gameContext);
			break;
		case Gameplay:
			currentState = new PlayState(gameContext);
			break;
		case GameOver:
			currentState = new GameoverState(gameContext);
			break;
		}

		//load new state
		currentState->Load();
	}

	nextState = currentState->Update(deltaTime);

	if(nextState == Quit)
	{
		currentState->Unload();
		delete currentState;
		return true;
	}
	return false;
}

void SGE_Render()
{
	currentState->Render();
}
